package com.gxa.jjty.cjr.service.impl;

import com.gxa.jjty.cjr.mapper.ArticleMapper;
import com.gxa.jjty.cjr.pojo.Article;
import com.gxa.jjty.cjr.service.ArticleService;
import com.gxa.jjty.core.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @author NITRO
 */
@Service("articleTitleService")
public class ArticleServiceImpl extends BaseServiceImpl<Article> implements ArticleService {

    @Autowired
    private ArticleMapper articleMapper;

    @Autowired
    RedisTemplate<String,Object> redisTemplate;


    private static final String KEY_PREFIX="articleList";




    @Override
    public List<Object> getArticle() {
//        List<Article> articles=null;
//        List<Article> range = Collections.singletonList((Article) redisTemplate.opsForList().range(KEY_PREFIX, 0, -1));
//        if (range==null) {
//            articles = articleMapper.selectAll();
//            return articles;
//        }else {
//            return range;
//        }
//        List<Object> articles=null;
//        articles =  redisTemplate.opsForList().range(KEY_PREFIX, 0, -1));

//        if (articles.size() <= 0) {
//            List<Article> articles1 = articleMapper.selectAll();
//            (redisTemplate.opsForList().leftPush(KEY_PREFIX,articles.toArray());
//            return articles1;
//        }else {
//            return articles;
//        }
        return  null;
    }
}
